<?php
/**
 * Builds up a programmatic model for SQL SET clause to be used by UPDATE query.
 */
class SQLUpdatesClause extends AbstractSQLClause {
	/**
	 * Sets up updates directly from constructor.
	 * 
	 * @example array("column1"=>new SQLValue("a'b"),"column2"=>"c")
	 * @param array(string=>SQLValue|string) $tblUpdates
	 */
	public function __construct($tblUpdates=array()) {
		if(sizeof($tblUpdates)) {
			foreach($tblUpdates as $key=>$value) {
				$this->tblContents[$key] = $value;
			}
		}
	}
	
	/**
	 * Transforms clause to string
	 * 
	 * @example column1='a''b', column2=c
	 * (non-PHPdoc)
	 * @see AbstractSQLClause::toString()
	 */
	public function toString() {
		$output = "";		
		foreach($this->tblContents as $strKey=>$mixValue) {
			$output .= $this->getValue($strKey)." = ".$this->getValue($mixValue).", ";
		}
		return substr($output,0,-2);
	}
}